import { defineStore } from 'pinia'
import { computed, ref } from 'vue'
type UserInfo = {
  name: string
  age: number
}
export const useUser = defineStore('user', () => {
  // setup方法  外部要用的数据你都要return
  // state
  const userInfo = ref<UserInfo>({ name: '张三', age: 18 })
  // actions
  const setUserInfo = (val: UserInfo) => {
    userInfo.value = val
  }
  // getters
  const getUserName = computed(() => {
    return userInfo.value.name
  })
  return { userInfo, setUserInfo, getUserName }
})
